﻿using EBA.IoC;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace EBA.Logging
{
    /// <summary>
    /// LogProvider utilities
    /// </summary>
    public static class LogProviderEx
    {


        /// <summary>
        /// Get a <see cref="ILogProvider"/> instance with specified name in config file.
        /// </summary>
        /// <returns></returns>
        public static ILogProvider GetInstance()
        {
         
           Configuration Config = AppRuntime.OpenConfiguration();

       
            var eba = Config.GetSectionGroup("eba");
            if (eba != null)
            {
                var log = eba.Sections.Get("log") as LoggingConfigurationSection;

                if (log != null)
                {
                    return Container.Default.GetExport<ILogProvider>(log.Provider);
                }
                else
                {
                    return new XmlFileLogProvider();
                }
            }
            else
            {
                return new XmlFileLogProvider();
            }
        }
    }
}
